﻿using System;
using System.Collections.Generic;
using System.Text;
using Emgu.CV;
using Emgu.CV.Structure;

namespace Domotica.Gazing
{
    class FaceTracker
    {
        public FaceTracker(Image<Gray, Byte> grayImage)
        {
            _GrayImage = grayImage;
        }

        private readonly Image<Gray, Byte> _GrayImage;
        public Image<Gray, Byte> GrayImage
        {
            get
            {
                if (_GrayImage == null)
                {
                }
                return _GrayImage;
            }
        }

        private FaceList _Faces;
        public FaceList Faces
        { 
            get
            {
                if (_Faces == null)
                {
                    _Faces = FaceRecognizer.FindFaces(GrayImage);
                }
                return _Faces;
            }
        }

        #region Methods

        public bool HasOneFace()
        {
            if (Faces.Count != 1)
                return false;
            Face face = Faces[0];
            return face.LeftEye != null && face.RightEye != null;
        }

        public void DrawFaces(Image<Bgr, Byte> image)
        {
            foreach (Face face in Faces)
            {
                face.Draw(image);
            }
        }

        public void DrawAllEyes(Image<Bgr, Byte> image)
        {
            foreach (Face face in Faces)
            {
                face.DrawAllEyes(image);
            }
        }

        public void DrawEyes(Image<Bgr, Byte> image)
        {
            foreach (Face face in Faces)
            {
                face.DrawEyes(image);
            }
        }

        #endregion
    }
}
